#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
    
int server(int p);
int client(int p);

main(int argc,char* argv[])
{
int rc, p[2];

    
    if (socketpair(AF_UNIX, SOCK_STREAM, 0, p) < 0)
    {
	printf("socketpair failed\n");
	exit(99);
    }
    if ((rc = fork()) == -1)
    {
	printf("fork failed\n");
	exit(99);
    }
    else if (rc)  /* parent */
    {
	close(p[1]);
	server(p[0]);
    }
    else
    {
	close(p[0]);
	client(p[1]);
    }
}

server(int p)
{
char buf[100];

    read(p,buf,999);
    printf("server: received %s\n",buf);
    strcpy(buf,"ack_from_server");
    write(p,buf,strlen(buf)+1);
}

client(int p)
{
char buf[100];

    gets(buf);
    write(p,buf,strlen(buf)+1);
    read(p,buf,999);
    printf("client: received %s\n",buf);
}
